package com.ye.controller;

import com.ye.domain.Music;
import com.ye.service.MusicSercices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RefreshScope
public class MusicController {
    @Autowired
    private MusicSercices musicSercices;

//    通过歌名搜索
    @GetMapping("/getMusicListByName")
    public List<Music> getMusicListByName(String songName){
        List<Music> musicListByName = musicSercices.getMusicListByName(songName);
        return musicListByName;
    }

//    通过歌名模糊搜索
    @GetMapping("/fuzzySearchMusic")
    public List<Music> fuzzySearch(String songName){
        List<Music> music = musicSercices.fuzzySearch(songName);
        return music;

    }

//    利用for循环进行歌曲的插入
    @PostMapping("/saveMusic")
    public void saveMusicData(@RequestBody Music music){
        musicSercices.saveMusicData(music);
    }

//    利用Mybatis的foreach来进行歌曲的插入
    @PostMapping("/batchSave")
    public void batchSave(@RequestBody List<Music> musicList){
        musicSercices.batchSave(musicList);
    }

    //    获取曲库歌曲数量
    @GetMapping("/countMusic")
    public Integer countMusicNum(){
        return musicSercices.countMusicNum();
    }

    //    随机12首歌曲
    @GetMapping("/randMusic")
    public List<Music> rand12(){
        return musicSercices.rand12();
    }



}
